package edu.whu.xterm.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class SharedPrefManager {

	public static final String TOP10_LATEST_REFRESH_TIME = "edu.whu.xterm.top10_latest_refresh";

	public static final String USER_NAME = "user_name";

	public static final String PASSWORD = "password";

	public static final String AUTO_LOGIN = "auto_login";

	public static final String REMEMBER_USER = "remember_user";

	public static final String FAVORITE_SAVED = "edu.whu.xterm.favorite_saved";

	private SharedPreferences pref;

	public SharedPrefManager(Context ctx) {
		pref = PreferenceManager.getDefaultSharedPreferences(ctx);
	}

	public void writePref(String key, String value) {
		Editor edit = pref.edit();
		edit.putString(key, value);
		edit.commit();
	}

	public void writePref(String key, int value) {
		Editor edit = pref.edit();
		edit.putInt(key, value);
		edit.commit();
	}

	public void writePref(String key, boolean value) {
		Editor edit = pref.edit();
		edit.putBoolean(key, value);
		edit.commit();
	}

	public void writePref(String key, long value) {
		Editor edit = pref.edit();
		edit.putLong(key, value);
		edit.commit();
	}

	public void writePref(String key, float value) {
		Editor edit = pref.edit();
		edit.putFloat(key, value);
		edit.commit();
	}

	public int readInt(String key) {
		return pref.getInt(key, -1);
	}

	public boolean readBoolean(String key) {
		return pref.getBoolean(key, false);
	}

	public boolean readBoolean(String key, boolean def) {
		return pref.getBoolean(key, def);
	}

	public float readFloat(String key) {
		return pref.getFloat(key, -1F);
	}

	public long readLong(String key) {
		return pref.getLong(key, -1L);
	}

	public String readString(String key) {
		return pref.getString(key, null);
	}

}
